package com.cfkj.vip.web.handler;

import com.cfkj.vip.entity.UserEntity;
import com.cfkj.vip.function.UserFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/loginController")
public class LoginController {
    @Autowired
    UserFunction fun;
    @RequestMapping("/login.do")
    public String Login(String account, String password, HttpServletRequest request){
        try {
            UserEntity en =fun.login(account, password);
            HttpSession session =request.getSession();
            session.setAttribute("currentUser",en);
        }catch (Exception e){
            request.setAttribute("message",e.getMessage());
            return "forward:/login.jsp";
        }
        return "redirect:/loginController/index.do";
    }
    @RequestMapping("/index.do")
    public String index(String name, HttpServletRequest request){
        request.setAttribute("request",name);
        return "index";
    }
}
